package cake.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import cake.dao.AdminDao;
import cake.entity.Admin;

public class AdminDaoImpl implements AdminDao{

	private JdbcTemplate db= new JdbcTemplate();
	
	private class AdminMapper implements RowMapper<Admin>{

		@Override
		public Admin mapRow(ResultSet rs) throws SQLException {
			return new Admin(rs.getInt("id"), rs.getString("userName"), rs.getString("passWord"), rs.getBoolean("status"));
		}
	}
	
	@Override
	public Admin checkLoginAdmin(String userName, String passWord) {
		return db.queryOne("select * from admin where username=? and password=? ", new AdminMapper(), userName,passWord);
	}

	@Override
	public boolean updateAdminStatus(Admin admin) {
		return db.update("update admin set status=? where username=?", admin.isStatus(), admin.getUserName());
	}
	
}
